package de.mpii.html;

import java.util.ArrayList;
import java.util.List;

import de.mpii.html.parser.TableParser;
import de.mpii.html.parser.TdParser;
import de.mpii.html.parser.TrParser;
import de.mpii.html.table.Row;
import de.mpii.html.table.Table;
import de.mpii.util.Uhtml;

public class Html {

	private final List<Table> tables = new ArrayList<Table>();
	private final List<Enumerate> enums = new ArrayList<Enumerate>();

	private final String html;

	public Html(String html) {
		this.html = html;
	}

	public void parse() {

		parseTables();
		parseEnums();
	}

	private void parseEnums() {

	}

	private void parseTables() {

		TableParser tp = new TableParser(html);

		String str1, str2, str3;

		while ((str1 = tp.next()) != null) {
			if (str1.trim().isEmpty())
				continue;

			Table table = new Table();

			TrParser trp = new TrParser(str1);

			while ((str2 = trp.next()) != null) {

				Row row = new Row(table);

				TdParser tdp = new TdParser(str2);

				while ((str3 = tdp.next()) != null) {

					row.add(Uhtml.strip(str3));

				}

				table.add(row);

			}

			tables.add(table);

			System.out.println(table);
		}

	}
}
